package edu.towson.cosc603.coffeemaker;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import junit.framework.TestCase;

/**
 
 **/
public class CoffeeMakerTest extends TestCase{
        private CoffeeMaker myCoffeeMaker;
        private Inventory inventory;
        private Recipe recipeLatte;
        private Recipe recipeVanila;
        private Recipe recipeMocha;
        private Recipe recipeCappuccino;
        private Recipe recipeCinnamon;
        
        /**
         Set up the Test Run by creating Objects.
          @throws Exception the exception
         **/
        
        @Before
        public void setUp() {
                myCoffeeMaker = new CoffeeMaker();
                inventory = new Inventory();
                
                
                recipeLatte = new Recipe();
                recipeLatte.setName("Latte");
                recipeLatte.setPrice(45);
                recipeLatte.setAmtCoffee(5);
                recipeLatte.setAmtMilk(2);
                recipeLatte.setAmtSugar(1);
                recipeLatte.setAmtChocolate(0);
                                 
                recipeVanila = new Recipe();
                recipeVanila.setName("Vanila");
                recipeVanila.setPrice(55);
                recipeVanila.setAmtCoffee(5);
                recipeVanila.setAmtMilk(1);
                recipeVanila.setAmtSugar(1);
                recipeVanila.setAmtChocolate(0);

             

                recipeMocha = new Recipe();
                recipeMocha.setName("Mocha");
                recipeMocha.setPrice(50);
                recipeMocha.setAmtCoffee(4);
                recipeMocha.setAmtMilk(1);
                recipeMocha.setAmtSugar(1);
                recipeMocha.setAmtChocolate(2);
                
                recipeCappuccino = new Recipe();
                recipeCappuccino.setName("Cappuccino");
                recipeCappuccino.setPrice(50);
                recipeCappuccino.setAmtCoffee(6);
                recipeCappuccino.setAmtMilk(1);
                recipeCappuccino.setAmtSugar(1);
                recipeCappuccino.setAmtChocolate(0);
                

                recipeCinnamon = new Recipe();
                recipeCinnamon.setName("Cinnamon");
                recipeCinnamon.setPrice(40);
                recipeCinnamon.setAmtCoffee(4);
                recipeCinnamon.setAmtMilk(1);
                recipeCinnamon.setAmtSugar(1);
                recipeCinnamon.setAmtChocolate(0);
                
        }
        
        
        /**
          Tear down.
          @throws Exception the exception
         **/
        
        @After
        public void tearDown() throws Exception {
                
        }

        
        

        /**
         This will test the AddRecipe method of CoffeeMaker
         PostCondition: This Test Run will be true if added recipe will match with the recipe name.
         **/     
        @Test public void testAddRecipe_Goods() {
                myCoffeeMaker.addRecipe(recipeLatte);
                assertEquals(recipeLatte, myCoffeeMaker.getRecipeForName("Latte"));           
        }

        /**
         This will test the AddRecipe method of CoffeeMaker for any Duplicate recipe
         PostCondition:This test Run will be false if it will try to add the recipe which is already present.
         **/  
        
        @Test 
        public void testAddRecipe_Duplicate() {
                myCoffeeMaker.addRecipe( recipeLatte);
                myCoffeeMaker.addRecipe(recipeVanila);
                myCoffeeMaker.addRecipe(recipeMocha);
                myCoffeeMaker.addRecipe(recipeCappuccino);
                assertFalse(myCoffeeMaker.addRecipe(recipeLatte));              
        }
        

        /**
         This will test the AddRecipe method of CoffeeMaker for the number of recipes that can be added.
         PostCondition: This test Run will be false if it will try to add more than 4 recipes.
         **/  
        
        @Test 
        public void testAddRecipe_Full() {
                myCoffeeMaker.addRecipe(recipeLatte);
                myCoffeeMaker.addRecipe(recipeVanila);
                myCoffeeMaker.addRecipe(recipeMocha);
                myCoffeeMaker.addRecipe(recipeCappuccino);
                assertFalse(myCoffeeMaker.addRecipe(recipeCinnamon));         
        }
        
        /**
         It will test the DeleteRecipe method of CoffeeMaker for a recipe that need to be deleted.
         PostCondition: This test Run will be true if it will try to delete a recipe that is present in the machine.
         **/  
        
        @Test   
        public void testDelRecipe1() {
                myCoffeeMaker.addRecipe(recipeCappuccino);
                assertTrue(myCoffeeMaker.deleteRecipe(recipeCappuccino));
        }

       
         /** This test method, DeleteRecipe will test for a null recipe of CofferMaker.
             PostCondition: The test Run will be false if it will try to delete a recipe that is null.
           **/ 
        
        @Test   
        public void testDelRecipe3() {
              
                Recipe newRecipe = null;
                assertFalse(myCoffeeMaker.deleteRecipe(newRecipe));
        }

        /**
         It will test the DeleteRecipe method of CoffeeMaker for a recipe to be deleted and which is not present in the machine.
         PostCondition:The test Run will be false if it will try to delete a recipe that is not present in the machine.
         **/     
        
        @Test   
        public void testDelRecipe2() {
               
                assertFalse(myCoffeeMaker.deleteRecipe(recipeCappuccino));
        }

        
        /**
         It will test the EditRecipe method of CoffeeMaker for a recipe to be edited.
         PostCondition: The test Run will be true if it will edit a correct recipe that is present in the machine.
         **/  
        
        @Test   
        public void testEditRecipe1() {
                myCoffeeMaker.addRecipe(recipeLatte);
                Recipe newRecipe = new Recipe();
                newRecipe = recipeLatte;
                newRecipe.setAmtSugar(5);
                assertTrue(myCoffeeMaker.editRecipe(recipeLatte, newRecipe));
        }
        
        /**
         It will test the EditRecipe method of CoffeeMaker for a recipe to be edited.
         PostCondition: The test will be false if it will try to edit a recipe that is not present in the machine.
         **/
        
        @Test   
        public void testEditRecipe2() {
                
                assertFalse(myCoffeeMaker.editRecipe(recipeLatte, recipeCappuccino));
        }
        
        
        /**
         It will test the addInventory method of CoffeeMaker for a recipe to be edited.
         PostCondition: The test will be true, if it will try to add positive amounts of Coffee,Milk,Sugar,Chocolate in the machine.
         **/     
        @Test   
        public void testaddInventory() {
                myCoffeeMaker.addInventory(1, 2, 3, 2);
                assertTrue(myCoffeeMaker.addInventory(1, 2, 3, 2));
        }
        

        /**
         It will test the addInventory method of CoffeeMaker for a recipe to be edited.
         PostCondition:The test will be false if it will try to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
         **/     
        @Test   
        public void testaddInventory_negative() {
                assertFalse(myCoffeeMaker.addInventory(-1, -11, -10, -13));
        }

        

        /**
         It will test the checkInventory method of CoffeeMaker for a recipe to be edited.
         PostCondition: The test will be false if it will try to add negative amounts of Coffee,Milk,Sugar,Chocolate in the machine.
         **/     
        @Test   
        public void testcheckInventory() {
                myCoffeeMaker.addInventory(3, 3, 5, 5);
                
                assertEquals(inventory.getCoffee(), myCoffeeMaker.checkInventory().getCoffee());
              
                assertEquals(inventory.getSugar(), myCoffeeMaker.checkInventory().getSugar());
                
                 assertEquals(inventory.getMilk(), myCoffeeMaker.checkInventory().getMilk());
                
                assertEquals(inventory.getChocolate(), myCoffeeMaker.checkInventory().getChocolate());
        }

        /**
          It will test the makeCoffee method.
         postCondition: The test will Run true if it will try to make the coffee with enough price amount.
         **/    
        
        @Test   
        public void testmakeCoffee() {
                assertEquals(10, myCoffeeMaker.makeCoffee(recipeCappuccino, 60));
        }
        
        /**
         It will test the makeCoffee method.
         PostCondition: It will run to test the returned money and inserted money are the same, if trying to make coffee without enough price amount.
         **/
        
        @Test   
        public void testmakeCoffee2() {
                assertEquals(35, myCoffeeMaker.makeCoffee(recipeCappuccino, 35));
        }
}